
package com.provafinal.service;

import com.provafinal.dao.AgendaDAO;
import com.provafinal.entity.Agenda;
import java.util.List;
import javax.inject.Inject;
import javax.validation.ValidationException;


public class AgendaService extends Service {

    @Inject
    private AgendaDAO agendaDAO;
    
    public void salvar(Agenda agenda) throws ValidationException {
        try {
            beginTransaction();
            agendaDAO.salvar(agenda);
            commitTransaction();
        } catch (RuntimeException e) {
            rollBackTransaction();
            throw e;
        }
    }

    public void alterar(Agenda agenda) throws ValidationException {
        try {
            beginTransaction();
            agendaDAO.alterar(agenda);
            commitTransaction();
        } catch (RuntimeException e) {
            rollBackTransaction();
            throw e;
        }
    }

    public void excluir(Integer agendaId) {
        try {
            beginTransaction();
            Agenda agenda = agendaDAO.carregar(agendaId, Agenda.class);
            agendaDAO.excluir(agenda);
            commitTransaction();
        } catch (RuntimeException e) {
            rollBackTransaction();
            throw e;
        }
    }

    public List<Agenda> listarAgenda() {
        return agendaDAO.listasAgenda();
    }
}
